package wangxiaotao.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;
import wangxiaotao.bean.vo.OrderVO;
import wangxiaotao.entity.Order;
import wangxiaotao.mapper.OrderMapper;
import wangxiaotao.service.OrderService;

import java.util.List;
import java.util.Map;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author wang
 * @since 2022-03-22
 */
@Service
@RequiredArgsConstructor
public class OrderServiceImpl extends ServiceImpl<OrderMapper, Order> implements OrderService {
    private final OrderMapper orderMapper;
    /**
     * 根据订单状态判断是否能修改订单数据
     * @param orderVO
     */
    @Override
    public void judgeOrderStatue(OrderVO orderVO) {
        //查询被操作订单的状态
        Order realOrder = orderMapper.selectOne(new QueryWrapper<Order>().select("order_statue").eq("id", orderVO.getId()));
        //订单状态不能后退
        if (realOrder.getOrderStatue().getStatue()>orderVO.getOrderStatue().getStatue()){
            throw new RuntimeException("订单状态不能回退！");
        }
    }

    @Override
    public void judgeOrderStatue(Integer[] orderIds) {
       //
    }

    /**
     * 获取最近7天销售额
     * @return
     */
    @Override
    public List<Map<String,Object>> getSaleForLast7() {
        return orderMapper.getSaleForLast7();
    }

}
